#pragma once
#include<iostream>
#include<map>

using namespace std;
#define MMSIZE 1000000

#include<cstdlib>
#include<stdio.h>
#include<ctime>

void tTest_MultiMap() {
	multimap<long, string> mm;

	char buf[10];
	clock_t timeStart = clock();
	cout << "开始时间: " << timeStart << endl;

	for (int i = 0; i < MMSIZE; i ++) {
		try {
			snprintf(buf, 10, "%d", rand());
			//multimap 不可使用 [] 做 insertion
			mm.insert(pair<long, string>(i, buf));	//将key-value组合成一个pair
		}
		catch (exception& p) {
			cout << "i = " << i << " " << p.what() << endl;
			abort();
		}
	}

	cout << "multimap 赋值所需要时间: " << clock() - timeStart << endl;
	cout << "multimap 大小: " << mm.size() << endl;
	cout << "multimap 最大大小: " << mm.max_size() << endl;

	long target;
	cin >> target;

	//使用multimap的find进行查找
	timeStart = clock();
	multimap<long, string>::iterator pItem = mm.find(target);
	cout << "multimap::find所需时间: " << clock() - timeStart << endl;

	//找到的结果迭代器中, first为key, second为value
	if (pItem != mm.end())
		cout << "找到元素: " << (*pItem).first << ": " << (*pItem).second << endl;	//pItem->second	(类似智能指针)
	else
		cout << "找不到" << endl;
}